package com.relax.mybatis.plugin.sensitive.strategy.impl;

import org.apache.commons.lang3.StringUtils;

import com.relax.mybatis.plugin.sensitive.strategy.SensitiveStrategy;

/**
 * @author relax
 * @date 2022/07/05
 * @desc 手机号码脱敏策略
 */
public class MobileSensitiveStrategy implements SensitiveStrategy {

    /**
     * <p>手机号码脱敏：显示前三后二位</p>
     *
     * <pre>
     * MobileSensitiveStrategy.handle("1234")        = "1234"
     * MobileSensitiveStrategy.handle("123456789ab") = "123******ab"
     * </pre>
     *
     * @param data
     * @param symbol
     * @return
     */
    @Override
    public String handle(String data, String symbol) {
        int length = StringUtils.length(data);
        if (length <= 5) {
            return data;
        }
        return StringUtils.rightPad(StringUtils.left(data, 3), length - 2, symbol)
                .concat(StringUtils.right(data, 2));
    }

}
